<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useMainStore } from '@/store/main'
import { useXxglStore } from '@/store/xxgl'
import dlgl from '@/api/dlgl'
import { ElMessage } from 'element-plus'
import { getFldmList } from '@/utils/get-fldm'
onMounted(() => {
  login()
})
const menus = [
  {
    index: '/index',
    title: '系统首页',
    qxzybh: '001',
  },
  {
    index: '/ajgd',
    title: '案件归档',
    qxzybh: '002001',
  },

  {
    index: '/jzsm',
    title: '集中扫描',
    qxzybh: '002002',
  },
  {
    index: '/jcgsh',
    title: '检察官审核',
    qxzybh: '002003',
  },
  {
    index: '/dacy',
    title: '档案初验',
    qxzybh: '002004',
  },
  {
    index: '/dafy',
    title: '档案复验',
    qxzybh: '002005',
  },
  {
    index: '/dagl',
    title: '档案管理',
    qxzybh: '002006',
  },
  {
    index: '/tgsh',
    title: '退改审批',
    qxzybh: '002007',
  },
  {
    index: '/wjrwgl',
    title: '文件任务管理',
    qxzybh: '002008',
  },
  {
    index: '/ajsdjc',
    title: '案件锁定解除',
    qxzybh: '002009',
  },
  {
    index: '/gdyj',
    title: '归档预警',
    qxzybh: '003001',
  },
  {
    index: '/jdtj',
    title: '监督统计',
    qxzybh: '003002',
  },
  {
    index: '/dajy',
    title: '档案借阅',
    qxzybh: '004001',
  },
  {
    index: '/jygl',
    title: '借阅管理',
    qxzybh: '004002',
  },
  {
    index: '/jysp',
    title: '借阅审批',
    qxzybh: '004003',
  },
  {
    index: '/dacx',
    title: '档案查询',
    qxzybh: '005001',
  },
  {
    index: '/datj',
    title: '档案统计',
    qxzybh: '005002',
  },
  {
    index: '/gdpz',
    title: '归档配置',
    qxzybh: '006001',
  },
  {
    index: '/yhqx',
    title: '用户权限',
    qxzybh: '006002',
  },
  {
    index: '/cqyjpz',
    title: '超期预警配置',
    qxzybh: '006003',
  },
  {
    index: '/sjbdcpz',
    title: '数据包导出配置',
    qxzybh: '006004',
  },
]
// 入参
const loading = ref<boolean>(false)
const route = useRoute()
const router = useRouter()
const store = useMainStore()
const xxStore = useXxglStore()
const login = () => {
  if (!route.query) {
    return
  }
  const params = {
    code: route.query.code || '',
  } as any
  loading.value = true
  dlgl
    .login(params)
    .then((res) => {
      xxStore.changeShow(true)
      const value = res.data as unknown as any
      store.saveUserInfo(value)
      const topMenu = menus.find((menu) =>
        res.data.cdqxList?.find((qx) => qx.qxzybh === menu.qxzybh),
      )
      if (topMenu) router.push(topMenu.index)
      getFldmList()
    })
    .catch((err) => {
      !err.isError && ElMessage({ type: 'warning', message: err.message })
    })
    .finally(() => {
      loading.value = false
    })
}
</script>
<template>
  <div class="container" v-loading="loading"></div>
</template>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  background: #fff;
}
</style>
